package com.ruoyi.activiti.modeler.support;

import org.activiti.bpmn.model.ActivitiListener;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.bpmn.parser.handler.UserTaskParseHandler;
import org.activiti.engine.impl.task.TaskDefinition;

/**
 * 设置全局监听器
 */
public class UserTaskParseHandlerSupport extends UserTaskParseHandler {
    protected void executeParse(BpmnParse bpmnParse, UserTask userTask) {
        super.executeParse(bpmnParse, userTask);
        TaskDefinition taskDefinition = (TaskDefinition)bpmnParse.getCurrentActivity().getProperty("taskDefinition");
        ActivitiListener activitiListener = new ActivitiListener();
//        activitiListener.setEvent(ActivitiEventType.TASK_CREATED.toString());
//        activitiListener.setEvent("create");
        activitiListener.setImplementationType("delegateExpression");
        activitiListener.setImplementation("${myUserTaskListener}");
        taskDefinition.addTaskListener("create",bpmnParse.getListenerFactory().createDelegateExpressionTaskListener(activitiListener));
    }
}